<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/js/ext/resources/css/ext-all.css"/>

    <script type="text/javascript" src="<?php echo base_url(); ?>assets/js/ext/adapter/ext/ext-base.js"; ?>"></script>
    <script type="text/javascript" src="<?php echo base_url(); ?>assets/js/ext/ext-all.js"; ?>"></script>
    <script type="text/javascript" src="<?php echo base_url(); ?>assets/js/ext/ext-lang-es.js"></script>
    <script type="text/javascript" src="<?php echo base_url(); ?>assets/js/ext/plugins/searchfield.js"; ?>"></script>
    <script type="text/javascript">
    var BASE_URL = '<?php echo base_url(); ?>' + 'index.php/';
    var BASE_PATH = '<?php echo base_url(); ?>';
    var BASE_ICONS = BASE_PATH + 'assets/icons/';
    Ext.onReady(function() {
      

        var strUsers = new Ext.data.Store({
            reader: new Ext.data.JsonReader({
                fields: [
                    'idProveedor', 'razon_social', 'nombre_fantasia', 'rut', 'giro', 'direccion', 'telefono', 'email', 'plazo_pago','nombre_ventas', 'cargo_ventas', 'fono_ventas', 'email_ventas','nombre_contabilidad', 'cargo_contabilidad',
                     'fono_contabilidad', 'email_contabilidad'
                ],
                root: 'rows', totalProperty: 'results'
            }),
            proxy: new Ext.data.HttpProxy({
                url: BASE_URL + 'proveedor/proveedorSelect',
                method: 'POST'
            })
        });

        var searchUsers = new Ext.app.SearchField({
            store: strUsers,
            params: {start: 0, limit: 10},
            width: 180,
            id: 'fieldUsersSearch'
        });

        var tbUsers = new Ext.Toolbar({
            items:[ {
                text: 'Guardar cambios',
                disabled: true,
                id: 'btnSave',
                icon: BASE_ICONS + 'save.gif',
                handler: updateUsers
            }, '->', searchUsers]
        });

        
        function updateUsers() {
            var sm = gridUsers.getSelectionModel();
            var sel = sm.getSelections();
            var data = '';
            for (i = 0; i<sel.length; i++) {
                data = data + sel[i].get('idProveedor') + ';'
                        + sel[i].get('razon_social')
                        + ';' + sel[i].get('nombre_fantasia')
                        + ';' + sel[i].get('rut')
                        + ';' + sel[i].get('giro')
                        + ';' + sel[i].get('direccion')
                        + '||';
            }
            Ext.Ajax.request({
                url: BASE_URL + 'proveedor/proveedorUpdate',
                method: 'POST',
                params: { postdata: data }
            });
            strUsers.load();
        }

        
        var cbGrid = new Ext.grid.CheckboxSelectionModel();

        var gridUsers = new Ext.grid.EditorGridPanel({
            frame: true, 
            title: 'Proveedor',
            border: true, 
            stripeRows: true,
            sm: cbGrid,
            store: strUsers,
            style: 'margin:0 auto;', height: 570, width: 1130,
            columns: [ 
                      cbGrid, {
                          header: "Razon social",
                          dataIndex: 'razon_social',
                          sortable: true,
                          editor: new Ext.form.TextField({
                              allowBlank: false
                          }),
                          width: 85
                      }, {
                    header: "Nombre fantasia",
                    dataIndex: 'nombre_fantasia',
                    sortable: true,
                    editor: new Ext.form.TextField({
                        allowBlank: false
                    }),
                    width: 85
                }, {
                    header: "Rut",
                    dataIndex: 'rut',
                    sortable: true,
                    editor: new Ext.form.TextField({
                        allowBlank: false
                    }),
                    width: 85
                }, {
                    header: "Giro",
                    dataIndex: 'giro',
                    sortable: true,
                    editor: new Ext.form.TextField({
                        allowBlank: false
                    }),
                    width: 85
                }, {
                    header: "Direccion",
                    dataIndex: 'direccion',
                    sortable: true,
                    editor: new Ext.form.TextField({
                        allowBlank: false
                    }),
                    width: 85
                }, {
                    header: "Telefono",
                    dataIndex: 'telefono',
                    sortable: true,
                    editor: new Ext.form.TextField({
                        allowBlank: false
                    }),
                    width: 85
                }, {
                    header: "Email",
                    dataIndex: 'email',
                    sortable: true,
                    editor: new Ext.form.TextField({
                        allowBlank: false
                    }),
                    width: 85
                }, {
                    header: "Plazo pago",
                    dataIndex: 'plazo_pago',
                    sortable: true,
                    editor: new Ext.form.TextField({
                        allowBlank: false
                    }),
                    width: 85
                }, {
                    header: "Nombre (V)",
                    dataIndex: 'nombre_ventas',
                    sortable: true,
                    editor: new Ext.form.TextField({
                        allowBlank: false
                    }),
                    width: 85
                }, {
                    header: "Cargo (V)",
                    dataIndex: 'cargo_ventas',
                    sortable: true,
                    editor: new Ext.form.TextField({
                        allowBlank: false
                    }),
                    width: 85
                }, {
                    header: "Telefono (V)",
                    dataIndex: 'fono_ventas',
                    sortable: true,
                    editor: new Ext.form.TextField({
                        allowBlank: false
                    }),
                    width: 85
                }, {
                    header: "Email (V)",
                    dataIndex: 'email_ventas',
                    sortable: true,
                    editor: new Ext.form.TextField({
                        allowBlank: false
                    }),
                    width: 85
                },{
                    header: "Nombre (C)",
                    dataIndex: 'nombre_contabilidad',
                    sortable: true,
                    editor: new Ext.form.TextField({
                        allowBlank: false
                    }),
                    width: 85
                }, {
                    header: "Cargo (C)",
                    dataIndex: 'cargo_contabilidad',
                    sortable: true,
                    width: 85
                }, {
                    header: "Telefono (C)",
                    dataIndex: 'fono_contabilidad',
                    sortable: true,
                    editor: new Ext.form.TextField({
                        allowBlank: false
                    }),
                    width: 85
                }, {
                    header: "Email (C)",
                    dataIndex: 'email_contabilidad',
                    sortable: true,
                    width: 85
                }
            ],
            listeners: {
                'rowclick': function() {
                    var sm = gridUsers.getSelectionModel();
                    var sel = sm.getSelections();
                    if (sel.length == 0) {
                        Ext.getCmp('btnSave').setDisabled(true);
                    } else {
                        Ext.getCmp('btnSave').setDisabled(false);
                    }
                }
            },
            tbar: tbUsers,
            bbar: new Ext.PagingToolbar({
                pageSize: 20,
                store: strUsers,
                displayInfo: true
            })
        });
        
        gridUsers.render('divgrid');
        strUsers.load();
    });
    </script>
    <style type="text/css">
        #divgrid {
            background: #e9e9e9;
            border: 1px solid #d3d3d3;
        }
    </style>

    <title></title>
</head>
<body>
    <div id="divgrid"></div>
</body>
</html>